/**
 * 通过interface自定义了一种数据格式
 */
// interface IStu {
//     id: number,
//     name: string,
//     classes: IClasses
// }
interface IClasses {
    id: number,
    name: string
}
interface IStu {
    id: number;
    name: string;
    classes: IClasses
}

let students:IStu[] = [
    { id: 1, name: "xiaowang", classes: { id: 1, name: "web33" } },
    { id: 2, name: "xiaofei", classes: { id: 1, name: "web33" } }
]

// 引入联合类型
type newState = IClasses | undefined
type newState2 = IClasses | IStu | undefined
type teacher = {
    id:number
}
//根据编号查询学生的班级，并返回
function find(id:number):newState {
    const stu = students.find(item=>item.id == id)
    const classes = stu?.classes
    return classes
}
find(3)

export { }

